home *** CD-ROM | disk | FTP | other *** search
/ Champak 122 / Vol 122.iso / games / sketchbo.swf / scripts / __Packages / XMLConstructNode.as < prev   
Encoding:
Text File  |  2011-01-06  |  1.9 KB  |  79 lines

  1. class XMLConstructNode
  2. {
  3.    var attributes;
  4.    var nodeName;
  5.    var _value;
  6.    function XMLConstructNode()
  7.    {
  8.    }
  9.    function appendChild(nName, sObj)
  10.    {
  11.       if(!(this[nName] instanceof Array))
  12.       {
  13.          this[nName] = [];
  14.          this[nName].__resolve = this.getFirstElement;
  15.       }
  16.       sObj.nodeName = nName;
  17.       this[nName].unshift(sObj);
  18.    }
  19.    function addAttribute(aName, aData)
  20.    {
  21.       if(this.attributes == undefined)
  22.       {
  23.          this.attributes = {};
  24.       }
  25.       this.attributes[aName] = aData;
  26.    }
  27.    function toXMLNode()
  28.    {
  29.       var _loc4_ = undefined;
  30.       var _loc2_ = undefined;
  31.       var _loc5_ = undefined;
  32.       var _loc3_ = undefined;
  33.       _loc4_ = new XML();
  34.       _loc3_ = _loc4_.createElement(this.nodeName);
  35.       for(_loc2_ in this.attributes)
  36.       {
  37.          _loc3_.attributes[_loc2_] = this.attributes[_loc2_];
  38.       }
  39.       _loc4_.appendChild(_loc3_);
  40.       _loc5_ = _loc4_.createTextNode(this._value);
  41.       _loc3_.appendChild(_loc5_);
  42.       return _loc3_;
  43.    }
  44.    function getFirstElement(f)
  45.    {
  46.       return this[0][f];
  47.    }
  48.    function parseConstruct(xObj, doc)
  49.    {
  50.       var _loc6_ = undefined;
  51.       var _loc4_ = undefined;
  52.       var _loc3_ = undefined;
  53.       var _loc2_ = undefined;
  54.       var _loc8_ = undefined;
  55.       var _loc9_ = undefined;
  56.       for(_loc6_ in xObj)
  57.       {
  58.          _loc3_ = xObj[_loc6_];
  59.          if(_loc3_ instanceof Array)
  60.          {
  61.             for(_loc4_ in _loc3_)
  62.             {
  63.                _loc2_ = _loc3_[_loc4_];
  64.                if(_loc2_ instanceof XMLConstructNode)
  65.                {
  66.                   doc.appendChild(_loc2_.toXMLNode());
  67.                   doc.lastChild.appendChild(this.parseConstruct(_loc2_,new XML()));
  68.                }
  69.             }
  70.          }
  71.       }
  72.       return doc;
  73.    }
  74.    function toXML()
  75.    {
  76.       return this.parseConstruct(this,new XML());
  77.    }
  78. }
  79.